home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / OLEMSG / TIMECARD.CLI / SERVER / REPORT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-07-16  |  13.3 KB  |  395 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "FLEXGRID.OCX"
  3. Begin VB.Form formReport 
  4.    Caption         =   "Report"
  5.    ClientHeight    =   4380
  6.    ClientLeft      =   885
  7.    ClientTop       =   2100
  8.    ClientWidth     =   9330
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4380
  11.    ScaleWidth      =   9330
  12.    Begin MSFlexGridLib.MSFlexGrid gridReport 
  13.       Height          =   3375
  14.       Left            =   120
  15.       TabIndex        =   4
  16.       Top             =   840
  17.       Width           =   7695
  18.       _ExtentX        =   13573
  19.       _ExtentY        =   5953
  20.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  21.          Name            =   "MS Sans Serif"
  22.          Size            =   8.25
  23.          Charset         =   1
  24.          Weight          =   400
  25.          Underline       =   0   'False
  26.          Italic          =   0   'False
  27.          Strikethrough   =   0   'False
  28.       EndProperty
  29.    End
  30.    Begin VB.CommandButton btnSave 
  31.       Caption         =   "&Save"
  32.       Height          =   375
  33.       Left            =   7920
  34.       TabIndex        =   3
  35.       Top             =   1320
  36.       Width           =   1212
  37.    End
  38.    Begin VB.CommandButton btnClose 
  39.       Caption         =   "&Close"
  40.       Height          =   375
  41.       Left            =   7920
  42.       TabIndex        =   1
  43.       Top             =   1800
  44.       Width           =   1212
  45.    End
  46.    Begin VB.CommandButton btnRemind 
  47.       Caption         =   "&Remind"
  48.       Enabled         =   0   'False
  49.       Height          =   375
  50.       Left            =   7920
  51.       TabIndex        =   0
  52.       Top             =   840
  53.       Width           =   1212
  54.    End
  55.    Begin VB.Label lblHeader 
  56.       Alignment       =   2  'Center
  57.       Caption         =   "Time Report for Pay Period Ending 1/1/2095"
  58.       BeginProperty Font 
  59.          Name            =   "MS Sans Serif"
  60.          Size            =   13.5
  61.          Charset         =   0
  62.          Weight          =   700
  63.          Underline       =   0   'False
  64.          Italic          =   0   'False
  65.          Strikethrough   =   0   'False
  66.       EndProperty
  67.       Height          =   495
  68.       Left            =   240
  69.       TabIndex        =   2
  70.       Top             =   120
  71.       Width           =   8775
  72.    End
  73. Attribute VB_Name = "formReport"
  74. Attribute VB_Base = "0{19C4F559-DF36-11CF-A520-00A0D1003923}"
  75. Attribute VB_GlobalNameSpace = False
  76. Attribute VB_Creatable = False
  77. Attribute VB_TemplateDerived = False
  78. Attribute VB_PredeclaredId = True
  79. Attribute VB_Exposed = False
  80. Option Explicit
  81. Dim aReport() As Double '3D : days x categories x users
  82. Dim cReceivedReports As Integer 'number of received reports
  83. Dim cReportCategories As Integer 'number of report categories in ReportCategorylist
  84. Dim ReportCategoryList As Variant 'Report categories
  85. Dim ReportPayPeriod As Date     'report payperiod
  86. Dim ReportDate() As Date        'when user sent the report
  87. Public Function CompileReport() As Boolean
  88. 'Iterates through all the report messages and extract info
  89. 'for the current pay period
  90. On Error GoTo error_olemsg
  91. Dim objReceivFolder As Object
  92. Dim objRepMsg As Object
  93. Dim objmessages As Object
  94. If Not frmCalender.GetDate(ReportPayPeriod) Then
  95.     Exit Function
  96. End If
  97. If objSession Is Nothing Then
  98.     MsgBox "Not logged on"
  99.     CompileReport = False
  100.     Exit Function
  101. End If
  102. 'get the receiving folder
  103. GetReceivIPCFolder objReceivFolder
  104. If objReceivFolder Is Nothing Then
  105.     MsgBox "Can't open receive folder"
  106.     CompileReport = False
  107.     Exit Function
  108. End If
  109. 'Get message collection from the receiving folder
  110. Set objmessages = objReceivFolder.Messages
  111. If objmessages Is Nothing Then
  112.     MsgBox "Failed to open folder's Messages collection"
  113.     CompileReport = False
  114.     Exit Function
  115. End If
  116. 'start iterating throuhg the messages
  117. Set objRepMsg = objmessages.getfirst(ReportMsgType)
  118. If objRepMsg Is Nothing Then
  119.     MsgBox "no report msgs found"
  120.     CompileReport = False
  121.     Exit Function
  122. End If
  123. cReceivedReports = 0
  124. Do While Not objRepMsg Is Nothing 'while there are messages
  125.     If Not ProcessMessage(objRepMsg) Then
  126.         CompileReport = False
  127.         Exit Function
  128.     End If
  129.     Set objRepMsg = Nothing
  130.     Set objRepMsg = objmessages.getnext 'next message
  131. CompileReport = True
  132. Exit Function
  133. error_olemsg:
  134.     MsgBox "Error " & Str(err) & ": " & Error$(err)
  135.     Resume Next
  136. End Function
  137. Function ProcessMessage(objmsg As Object) As Boolean
  138. 'If the message is for the right pay period extract and store info
  139. On Error GoTo error_olemsg
  140. Dim tmpPayPeriod As Date
  141. Dim tmpcRepCats As Integer
  142. Dim tmpRepCats As Variant
  143. Dim ind As Integer
  144. Dim PropName As String
  145. Dim var As Variant
  146. Dim day As Integer
  147. Dim userindex As Integer
  148. Dim usrName As String
  149. Dim response As Integer
  150. Dim objFields As Object
  151. Dim msgSentDate As Date
  152. 'Get msg's fields collection
  153. Set objFields = objmsg.Fields
  154. If objFields Is Nothing Then
  155.     ProcessMessage = True 'ignore this msg
  156.     Exit Function
  157. End If
  158. 'get the pay-period
  159. tmpPayPeriod = objFields.Item(PayPeriodPropName)
  160. If tmpPayPeriod <> ReportPayPeriod Then
  161.     ProcessMessage = True   'not intrested in this one
  162.     Exit Function
  163. End If
  164. objmsg.Unread = False
  165. objmsg.Update
  166. If cReceivedReports = 0 Then 'first report, has to get the categ. lits
  167.     cReportCategories = objFields.Item(NumCatPropName).Value
  168.     If cReportCategories = 0 Then
  169.         Debug.Print "impossible happend: cReportCats = 0"
  170.         Exit Function
  171.     End If
  172.     ReportCategoryList = objFields.Item(CatPropName).Value
  173.     ReDim aReport(7, cReportCategories, UserList.cUsers)
  174.     ReDim ReportDate(UserList.cUsers)
  175. Else 'let's do some validation
  176.     tmpcRepCats = objFields.Item(NumCatPropName).Value
  177.     If tmpcRepCats <> cReportCategories Then
  178.         Debug.Print "number of categories do not match, skipping this message..."
  179.         ProcessMessage = True
  180.         Exit Function
  181.     End If
  182.     tmpRepCats = objFields.Item(CatPropName).Value
  183.     For ind = 0 To tmpcRepCats
  184.         If tmpRepCats(ind) <> ReportCategoryList(ind) Then
  185.             Debug.Print "categories do not match, skipping message..."
  186.             ProcessMessage = True
  187.             Exit Function
  188.         End If
  189.     Next ind
  190. End If
  191. usrName = objmsg.sender.Name
  192. 'usrName = objFields.Item(NamePropName).Value
  193. userindex = FindUser(usrName)
  194. If E_NOT_FOUND = userindex Then 'the user is not on the list
  195.     response = MsgBox("Received a report from user " & usrName & _
  196.             " who is not on the user list." & Chr(13) & _
  197.             "Would you like to add him/her to the list?", _
  198.             vbYesNo + vbQuestion)
  199.     If response = vbYes Then
  200.         'allocate space for the new guy
  201.         ReDim Preserve UserList.aUsers(UserList.cUsers + 1)
  202.         ReDim Preserve aReport(7, cReportCategories, UserList.cUsers + 1)
  203.         ReDim Preserve ReportDate(UserList.cUsers + 1)
  204.         
  205.         'enter him in the list
  206.         UserList.aUsers(UserList.cUsers).DisplayName = usrName
  207.         UserList.aUsers(UserList.cUsers).EntryID = objmsg.sender.id
  208.         UserList.aUsers(UserList.cUsers).ReportIndex = E_NOT_FOUND
  209.         
  210.         'set the index
  211.         userindex = UserList.cUsers
  212.         
  213.         UserList.cUsers = UserList.cUsers + 1
  214.         
  215.     Else
  216.         ProcessMessage = True  'don't care about this one
  217.         Exit Function
  218.     End If
  219. End If
  220. 'If we are here, everything is cool. Get the data.
  221. 'remember when the msg was sent
  222. msgSentDate = objmsg.timesent
  223. If UserList.aUsers(userindex).ReportIndex = E_NOT_FOUND Then
  224.     'if first report from the user
  225.     For ind = 1 To cReportCategories Step 1
  226.         PropName = RepDataPropPrefix & Str(ind)
  227.         var = objFields.Item(PropName)
  228.         For day = 0 To 6 Step 1
  229.             aReport(day, ind - 1, cReceivedReports) = var(day)
  230.         Next day
  231.     Next ind
  232.     UserList.aUsers(userindex).ReportIndex = cReceivedReports
  233.     ReportDate(userindex) = msgSentDate
  234.     cReceivedReports = cReceivedReports + 1
  235.     'if there are more than one report from the same user, user the
  236.     'one that was sent later
  237.     '$
  238.     'make the two loops into one, when sure that they work
  239.     Debug.Print "There is more than one report from " & usrName
  240.     If msgSentDate > ReportDate(userindex) Then
  241.         For ind = 1 To cReportCategories Step 1
  242.             PropName = RepDataPropPrefix & Str(ind)
  243.             var = objFields.Item(PropName)
  244.             For day = 0 To 6 Step 1
  245.                 aReport(day, ind - 1, UserList.aUsers(userindex).ReportIndex) = var(day)
  246.             Next day
  247.         Next ind
  248.         ReportDate(userindex) = msgSentDate
  249.     End If
  250. End If
  251. ProcessMessage = True
  252. Exit Function
  253. error_olemsg:
  254.     MsgBox "Error " & Str(err) & ": " & Error$(err)
  255.     Resume Next
  256. End Function
  257. Function FindUser(strName As String) As Integer
  258. 'finds user's positions in the user list given user name
  259. Dim ind As Integer
  260. ind = 0
  261. Do While ind < UserList.cUsers
  262.     If UserList.aUsers(ind).DisplayName = strName Then
  263.         FindUser = ind
  264.         Exit Function
  265.     End If
  266.     ind = ind + 1
  267. FindUser = E_NOT_FOUND
  268. Exit Function
  269. End Function
  270. Sub ShowGrid()
  271. 'uses the extracted data to display the report
  272. Const strNoData As String = "No data"
  273. Const FirstColW As Integer = 2250
  274. Const BorderW As Integer = 30
  275. Dim strDays As Variant
  276. Dim indDays As Integer
  277. Dim indCats As Integer
  278. Dim indUsrs As Integer
  279. Dim indRprt As Integer
  280. Dim sum As Double
  281. Dim total As Double
  282. Dim CellW As Double
  283. strDays = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Total")
  284. gridReport.Cols = 9 'number of elements in strDays+1
  285. gridReport.Rows = UserList.cUsers + 1
  286. 'resize columns
  287. CellW = (gridReport.Width - FirstColW - BorderW * gridReport.Cols) _
  288.             / (gridReport.Cols - 1)
  289. gridReport.ColWidth(0) = FirstColW
  290. For indDays = 1 To gridReport.Cols - 1
  291.     gridReport.ColWidth(indDays) = CellW
  292. Next indDays
  293. 'display the first row
  294. gridReport.Row = 0
  295. For indDays = 0 To gridReport.Cols - 2
  296.     gridReport.Col = indDays + 1
  297.     gridReport.Text = strDays(indDays)
  298. Next indDays
  299. 'display the rest of the grid
  300. For indUsrs = 0 To UserList.cUsers - 1 'for all users
  301.     indRprt = UserList.aUsers(indUsrs).ReportIndex
  302.     gridReport.Row = indUsrs + 1
  303.     gridReport.Col = 0
  304.     gridReport.Text = UserList.aUsers(indUsrs).DisplayName
  305.     total = 0
  306.     For indDays = 0 To 6 'for each day
  307.         gridReport.Col = indDays + 1
  308.         If indRprt = E_NOT_FOUND Then
  309.             'no report received from this user
  310.             gridReport.Text = strNoData
  311.             btnRemind.Enabled = True
  312.         Else
  313.             sum = 0 'sum for cats per day
  314.             For indCats = 0 To cReportCategories - 1
  315.                 sum = sum + aReport(indDays, indCats, indRprt)
  316.             Next indCats
  317.             gridReport.Text = Str(sum)
  318.             total = total + sum 'total for the week
  319.         End If
  320.     Next indDays
  321.     'last column is total
  322.     gridReport.Col = gridReport.Cols - 1
  323.     If indRprt <> E_NOT_FOUND Then
  324.         gridReport.Text = Str(total)
  325.     Else
  326.         gridReport.Text = strNoData
  327.     End If
  328. Next indUsrs
  329. lblHeader = "Time Report for Pay Period Ending " & ReportPayPeriod
  330. End Sub
  331. Private Sub btnClose_Click()
  332.     Unload Me
  333. End Sub
  334. Private Sub btnRemind_Click()
  335. 'sends second request message to the users who haven't submitted report
  336. Dim ind As Integer
  337. Dim tmpCats() As String
  338. ReDim tmpCats(cReportCategories)
  339. 'put all the cats from variant into a string array
  340. For ind = 0 To cReportCategories - 1
  341.     tmpCats(ind) = ReportCategoryList(ind)
  342. Next ind
  343. formmainsvr.SendRequest cReportCategories, tmpCats, _
  344.             ReportPayPeriod, True
  345. End Sub
  346. Private Sub btnSave_Click()
  347. 'save report
  348. On Error GoTo CheckError
  349. Dim indUsrs As Integer
  350. Dim indRprt As Integer
  351. Dim indDays As Integer
  352. Dim indCats As Integer
  353. Open "Report.dat" For Output As #1
  354. Print #1, Tab(24); "Time Report"
  355. Print #1, Tab(20); "Pay period ending " & ReportPayPeriod
  356. For indUsrs = 0 To UserList.cUsers - 1
  357.     Print #1,
  358.     Print #1,
  359.     Print #1, "======================================================================"
  360.     Print #1, "Employee: ", UserList.aUsers(indUsrs).DisplayName
  361.     indRprt = UserList.aUsers(indUsrs).ReportIndex
  362.     If Not indRprt = E_NOT_FOUND Then
  363.         Print #1, Tab(20); _
  364.            "Sun     Mon     Tue     Wed     Thu     Fri     Sat"
  365.         For indCats = 0 To cReportCategories - 1
  366.             Print #1, ReportCategoryList(indCats), Tab(20);
  367.             For indDays = 0 To 6
  368.                 Print #1, aReport(indDays, indCats, indRprt); Tab(20 + (1 + indDays) * 8);
  369.             Next indDays
  370.             Print #1,
  371.         Next indCats
  372.     Else
  373.         Print #1, "No data submitted"
  374.     End If
  375. Next indUsrs
  376. Close #1
  377. Exit Sub
  378. CheckError:
  379. MsgBox "Error saving user list"
  380. End Sub
  381. Private Sub Form_Load()
  382.     ShowGrid
  383. End Sub
  384. Private Sub Form_Unload(Cancel As Integer)
  385. 'deinit variables global to this module
  386. Dim ind As Integer
  387. For ind = 0 To UserList.cUsers - 1
  388.     UserList.aUsers(ind).ReportIndex = E_NOT_FOUND
  389. Next ind
  390. cReceivedReports = 0
  391. cReportCategories = 0
  392. ReportPayPeriod = Date
  393. ReDim aReport(0, 0, 0)
  394. End Sub
  395.